#!/usr/bin/env python

import sys
import re
from urllib import urlopen, urlencode

URL = 'http://whereareyoucamping0.appspot.com'

def put(key, value):
    params = {'key': '"' + key + '"', 'value': value}
    print urlopen(URL + '/put?' + urlencode(params), '').read()

args = sys.argv[1:]
if args:
    put(args[0], args[1])
else:
    while True:
        line = sys.stdin.readline()
        if not line:
            break
        test = False
        if line.startswith('t'):
            line = line[1:]
            test = True
        if line.startswith('2011-'):
            line = line.split(' ', 2)[2]
        key, value = line.split(' ', 1)
        value = value[value.index('{'):]
        if test:
            key = 'test__'
            value = re.sub(r'}\s*$', ', "title": "- TEST -"}', value)
        put(key, value)
